<?php


namespace addons\facrm\library\queue;

use app\common\library\Email;
use think\Exception;
use think\Log;
use think\queue\job;

class EmailJob
{
    public function fire(Job $job, $data){

        if ($job->attempts() > 3) {
            //通过这个方法可以检查这个任务已经重试了几次了
            $job->delete();
            return;
        }

        $email = new Email();

        $result= $email->subject($data['subject'])
            ->to($data['to'])// $email 收件人,多个收件人以,进行分隔
            ->message($data['message'])
            ->send();
        \addons\facrm\model\Notices::add($data,"Email",$result?1:'0',$email->getError());
        $job->delete();
        return $result;

    }

    public function failed($data){
        Log::write("邮件任务失败：".print_r(['data' => $data,],true),'error');
    }

}